﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Procedure = DeltaFlex.Data.ConsProcedures.Client;

namespace DeltaFlex.Data
{
    public class Client
    {
        public Client()
        { }

        #region Inserts
        public static int InsertarClient(string nomClient, string nifClient, int telefonClient, int faxClient, string email, string numCompte, string FormaPago,
                                         string carrerNumero, string poligon, string ciutat, int codiPostal, string provincia, string pais)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_INSERTARCLIENT;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_NOMCLIENT, nomClient);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_NIFCLIENT, nifClient);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_TELEFONCLIENT, telefonClient);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_FAXCLIENT, faxClient);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_EMAIL, email);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_NUMCOMPTE, numCompte);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_FORMAPAGO, FormaPago);

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_CARRERNUMERO, carrerNumero);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_POLIGON, poligon);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_CIUTAT, ciutat);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_CODIPOSTAL, codiPostal);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_PROVINCIA, provincia);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_PAIS, pais);

            return Operacions_BD.Insertar(cmd);
        }
        #endregion

        #region Selects
        /// <summary>
        /// Llista els clients segons el seu seu id. 
        /// </summary>
        /// <param name="idClient">Si idClient = 0, llavors llista tots els clients.
        /// En cas contrari, llista el client amb el idClient rebut</param>
        /// <returns>Retorna una llista de clients segons el seu id</returns>
        public static IDataReader LlistarClientsByIDClient(int idClient)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_CERCAR_CLIENT_BY_IDCLIENT;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IDCLIENT, idClient);

            return Operacions_BD.Reader(cmd);
        }
        #endregion

    }
}
